package com.jackyzgy.test.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

public class Server {

	public static void main(String[] args) throws IOException {
		List<String> loglist = new ArrayList<String>();
		loglist.add(">>>>>>>我是张光盈<<<<<<<");
		loglist.add(">>>>>>>我是池丹鸿<<<<<<<");
		loglist.add(">>>>>>>我是池丹鸿<<<<<<<");
		
		StringBuffer stringBuffer = new StringBuffer("[");
		
//		String jsonStr = "[{content:'fdsfds'},{content:'gfdjfgf'}]";
		
		for (int i = 0; i < loglist.size(); i++) {
			stringBuffer.append("{content:'");
			stringBuffer.append(loglist.get(i));
			stringBuffer.append("'}");
			if (i != loglist.size()-1) {
				stringBuffer.append(",");
			}
		}
		stringBuffer.append("]");

		ServerSocket server = new ServerSocket(30000);
		while(true){
			Socket socket = server.accept();
			
			while(true){
				ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
				objectOutputStream.writeObject(loglist);
				objectOutputStream.close();
			}
			
//			PrintStream printStream = new PrintStream(socket.getOutputStream());
//			printStream.println(loglist);
//			printStream.flush();
			
//			BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
//		    String requestStr = reader.readLine();
//		    System.out.println(requestStr);
//		    
//		    reader.close();
//		    printStream.close();
//		    socket.close();
		}
	}
}
